<?php

/**
 * Laravel-admin - admin builder based on Laravel.
 * @author z-song <https://github.com/z-song>
 *
 * Bootstraper for Admin.
 *
 * Here you can remove builtin form field:
 * Encore\Admin\Form::forget(['map', 'editor']);
 *
 * Or extend custom form field:
 * Encore\Admin\Form::extend('php', PHPEditor::class);
 *
 * Or require js and css assets:
 * Admin::css('/packages/prettydocs/css/styles.css');
 * Admin::js('/packages/prettydocs/js/main.js');
 *
 */

use App\Admin\Extensions\AceEditor;
use App\Admin\Extensions\WangEditor;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid\Column;

Admin::css('/admin_assets/css/admin_base.css');
Admin::js('/admin_assets/layer/layer.js');
Admin::js('/admin_assets/js/admin_base.js');


Encore\Admin\Form::forget(['map']);
Form::extend('editor', WangEditor::class);
Form::extend('ace_editor', AceEditor::class);

Column::extend('thumb', function ($value, $w = 100, $h = 100) {
    return "<a target='_blank' href='" . \App\Helpers\FileTool::thumb($value) . "'><img class='thumb' width='$w' height='$h' src='" . \App\Helpers\FileTool::thumb($value, 'imageView2/1/w/' . $w . '/h/' . $h . '/q/100') . "'/></a>";
});

Column::extend('thumbs', function ($values, $w = 100, $h = 100) {
    $values = json_decode($values, true);
    $values = array_map(function ($value) use ($h, $w) {
        return "<a target='_blank' href='" . \App\Helpers\FileTool::thumb($value) . "'><img class='thumb mr5' width='$w' height='$h' src='" . \App\Helpers\FileTool::thumb($value, 'imageView2/1/w/' . $w . '/h/' . $h . '/q/100') . "'/></a>";
    }, $values);


    return join('', $values);

});

Column::extend('type_name', function ($value, $array) {
    return $array[$value];
});
